
import ac = module("utils/commons/array-collection");
import an = module("main/org/sdmx/model/v2/base/Annotation");
import ut = module("utils/utils");
/**
	* A collection of annotations. It extends the AS3 ArrayCollection
	* and simply restrict the items type to Annotation.
	* 
	* @author Xavier Sosnovsky, Anthony Morel
	* 
	* @see Annotation
	* @see AnnotableArtefact
	* 
	* @todo 
	* 		make sure we don't allow duplicates.
	*/
export class AnnotationsCollection extends ac.ArrayCollection<an.Annotation> {

	/*==============================Fields================================*/
		
	private static ERROR_MSG:string = "Only annotations are " + 
			"allowed in a collection of annotations. Got: ";

	/*===========================Constructor==============================*/
						
	constructor(source=null) {
		super(source);
	}
		
	/*==========================Public methods============================*/
		
	/**
		* @private 
		*/
	public addItemAt(item:an.Annotation, index:number):ac.ArrayCollection<an.Annotation> {
		if (!(item instanceof an.Annotation)) {
			throw new Error(AnnotationsCollection.ERROR_MSG + 
					ut.Utils.getQualifiedClassName(item) + ".");
		} else {
			return super.addItemAt(item, index);
		}
	}
    
    /**
        * @private 
        */
    public setItemAt(item: an.Annotation, index: number): ac.ArrayCollection<an.Annotation> {
		if (!(item instanceof an.Annotation)) {
			throw new Error(AnnotationsCollection.ERROR_MSG + 
					ut.Utils.getQualifiedClassName(item) + ".");
		}
		return super.setItemAt(item, index);
	}
}